<!DOCTYPE html>
<html lang="en">
<head>
    <title>教务管理员</title>
    <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/css/font-awesome.css" rel="stylesheet" />
    <link href="static/css/style.css" rel="stylesheet" />
    <link href="static/css/lcy_css.css" rel="stylesheet" />
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
</head>
    <div class="container">
        <div class="row">
            <div class="row">
                <div class="col-sm-10 col-md-10 col-lg-10">
                    <h1>
                        学生选课和成绩管理系统
                    </h1>
                </div>
                <div class="col-sm-2 col-md-2 col-lg-2">
                    <p name="adm_username" id="adm_username">{{adm}}</p>
                    <button type="button" class="btn btn-link" data-toggle="modal" data-target="#update_password">
                        修改密码
                    </button>
                    <button type="button" class="btn btn-link" onclick="log_out()">
                        退出登录
                    </button>
                </div>
            </div>
            <div class="modal fade" id="update_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">修改密码</h4>
                        </div>
                        <div class="modal-body">
                            <form role="form" method="post" id="lc_up_pass">
                                <div class="form-group">
                                    <label for="password1">密码</label>
                                    <input type="password" class="form-control" id="password1" name="password1" placeholder="">
                                </div>
                                <div class="form-group">
                                    <label for="password2">确认密码</label>
                                    <input type="password" class="form-control" id="password2" name="password2" placeholder="">
                                </div>
                                <div>
                                    <button type="button" class="btn btn-default" onclick="up_ps()">
                                        确认
                                    </button>
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        关闭
                                    </button>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
        </div>
        <div class="row panel panel-success">
            <ul class="nav nav-tabs">
                <li class="active"><a data-toggle="tab" href="#stu_main">学生信息维护</a></li>
                <li><a data-toggle="tab" href="#tea_main">开课数据维护</a></li>
            </ul>
        </div>
        <div class="row tab-content">
            <div id="stu_main" class="tab-pane fade in active">
                <div class="col-sm-4 col-md-4 col-lg-4 panel panel-success" style="padding-bottom:10px">
                    <form role="form"id="lc_stu">
                        <div class="form-group">
                            <label for="xh">学号:</label>
                            <input type="text" class="form-control" id="xh" name="xh" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label for="xm">姓名:</label>
                            <input type="text" class="form-control" id="xm" name="xm">
                        </div>
                        <div class="form-group">
                            <label for="xb_xb">性别:</label>
                            <div class="form-control" id="xb_xb" name="xb_xb">
                                <div class="radio-inline">
                                    <label>
                                         <input type="radio" name="xb" id="xb_nan" value="男">男
                                    </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                         <input type="radio" name="xb" id="xb_nv" value="女">女
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sr">生日:</label>
                            <input type="text" class="form-control" name="sr" id="sr">
                        </div>
                        <div class="form-group">
                            <label for="bj">班级:</label>
                            <select id="bj" class="form-control" name="bj">
                                {% for i in clas[0] %}
                                <option>
                                    {{i[1]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="mm">密码:</label>
                            <input type="text" class="form-control" name="mm" id="mm">
                        </div>
                        <div class="form-group">
                            <div class="col-sm-6 col-md-6 col-lg-6">
                                <button type="button" class="btn btn-default form-control" onclick="cr_stu()">
                                    添加新学生
                                </button>
                            </div>
                            <div class="col-sm-6 col-md-6 col-lg-6">
                                <button type="button" class="btn btn-default form-control" onclick="up_stu()">
                                    修改学生信息
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="col-sm-8 col-md-8 col-lg-8">
                    <form class="form-inline" role="form" id="stu_search">
                        <div class="form-group">
                            <label for="ser_xh">学号</label>
                            <input type="text" class="form-control" name="ser_xh" id="ser_xh">
                        </div>
                        <div class="form-group">
                            <label for="ser_xm">姓名</label>
                            <input type="text" class="form-control" name="ser_xm" id="ser_xm">
                        </div>
                        <div class="form-group">
                            <label for="ser_bj">班级</label>
                            <select id="ser_bj" class="form-control" name="ser_bj">
                                <option value="">
                                    全部
                                </option>
                                {% for i in clas[0] %}
                                <option>
                                    {{i[1]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-default form-control" onclick="ser_stu()">
                                查询
                            </button>
                        </div>
                    </form>
                    <div class="row lcytable">
                        <table class="table table-striped table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th>修改</th>
                                    <th>学号</th>
                                    <th>姓名</th>
                                    <th>班级</th>
                                    <th>性别</th>
                                    <th>出生日期</th>
                                    <th>密码</th>
                                    <th>删除</th>
                                </tr>
                            </thead>
                            <tbody id="stu_tbody">
                                {% for i in stus[0] %}
                                <tr id="stu{{i[0]}}">
                                    <td>
                                        <button type="button" class="btn btn-link" onclick="to_stu({{i[0]}})">
                                            <span class="glyphicon glyphicon-arrow-left" style="color: Green"></span>
                                        </button>
                                    </td>
                                    <td id="stu_xh{{i[0]}}">
                                        {{i[0]}}
                                    </td>
                                    <td id="stu_xm{{i[0]}}">
                                        {{i[2]}}
                                    </td>
                                    <td id="stu_bj{{i[0]}}">
                                        {{i[3]}}
                                    </td>
                                    <td id="stu_xb{{i[0]}}">
                                        {{i[4]}}
                                    </td>
                                    <td id="stu_cs{{i[0]}}">
                                        {{i[5]}}
                                    </td>
                                    <td id="stu_mm{{i[0]}}">
                                        {{i[1]}}
                                    </td>
                                    <td>
                                        <button type="button" class="btn btn-link" onclick="del_stu({{i[0]}})">
                                            <span class="glyphicon glyphicon-remove" style="color: Red"></span>
                                        </button>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div id="tea_main" class="tab-pane fade">
                <div class="col-sm-4 col-md-4 col-lg-4 panel panel-success " style="padding-bottom:10px">
                    <form role="form" id="lc_op">
                        <div class="form-group">
                            <label for="bh">编号:</label>
                            <input type="text" class="form-control" name="bh" id="bh" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label for="kh">课号:</label>
                            <select id="kh" class="form-control" name="kh">
                                {% for i in cous[0] %}
                                <option value="{{i[0]}}">
                                    {{i[0]}} {{i[1]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="js">教师:</label>
                            <select id="js" class="form-control" name="js">
                                {% for i in teas[0] %}
                                <option value="{{i[0]}}">
                                    {{i[0]}} {{i[2]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="cl">班级:</label>
                            <select id="cl" class="form-control" name="cl">
                                {% for i in clas[0] %}
                                <option value="{{i[0]}}">
                                    {{i[0]}} {{i[1]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="xs">学时:</label>
                            <input type="number" class="form-control" name="xs" id="xs">
                        </div>
                        <div class="form-group">
                            <label for="xf">学分:</label>
                            <input type="number" class="form-control" name="xf" id="xf">
                        </div>
                        <div class="form-group">
                            <label for="rl">课容量:</label>
                            <input type="number" class="form-control" name="rl" id="rl">
                        </div>
                        <div class="form-group">
                            <div class="col-sm-6 col-md-6 col-lg-6" >
                                <button type="button" class="btn btn-default form-control" onclick="cr_open()">
                                    开课
                                </button>
                            </div>
                            <div class="col-sm-6 col-md-6 col-lg-6">
                                <button type="button" class="btn btn-default form-control" onclick="up_open()">
                                    修改
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="col-sm-8 col-md-8 col-lg-8 lcytable">
                    <form class="form-inline" role="form" id="open_search">
                        <div class="form-group">
                            <label for="ope_kh">课号</label>
                            <select id="ope_kh" class="form-control" name="ope_kh">
                                <option value="">
                                    全部
                                </option>
                                {% for i in cous[0] %}
                                <option value="{{i[0]}}">
                                    {{i[0]}} {{i[1]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="ope_js">教师</label>
                            <select id="ope_js" class="form-control" name="ope_js">
                                <option value="">
                                    全部
                                </option>
                                {% for i in teas[0] %}
                                <option value="{{i[0]}}">
                                    {{i[0]}} {{i[2]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="ope_bj">班级</label>
                            <select id="ope_bj" class="form-control" name="ope_bj">
                                <option value="">
                                    全部
                                </option>
                                {% for i in clas[0] %}
                                <option value="{{i[0]}}">
                                    {{i[0]}} {{i[1]}}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-default form-control" onclick="ser_open()">
                                查询
                            </button>
                        </div>
                    </form>
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>修改</th>
                                <th>编号</th>
                                <th>课号</th>
                                <th>教师</th>
                                <th>班级</th>
                                <th>学时</th>
                                <th>学分</th>
                                <th>课容量</th>
                                <th>日期</th>
                                <th>删除</th>
                            </tr>
                        </thead>
                        <tbody id="open_tbody">
                            {% for i in opens[0] %}
                            <tr  id="open{{i[0]}}">
                                <td>
                                    <button type="button" class="btn btn-link" onclick="to_open({{i[0]}})">
                                        <span class="glyphicon glyphicon-arrow-left" style="color: Green"></span>
                                    </button>
                                </td>
                                <td id='op_bh{{i[0]}}'>
                                    {{i[0]}}
                                </td>
                                <td id='op_kh{{i[0]}}'>
                                    {{i[1]}}
                                </td>
                                <td id='op_js{{i[0]}}'>
                                    {{i[2]}}
                                </td>
                                <td id='op_cl{{i[0]}}'>
                                    {{i[3]}}
                                </td>
                                <td id='op_xs{{i[0]}}'>
                                    {{i[4]}}
                                </td>
                                <td id='op_xf{{i[0]}}'>
                                    {{i[5]}}
                                </td>
                                <td id='op_rl{{i[0]}}'>
                                    {{i[6]}}
                                </td>
                                <td id='op_date{{i[0]}}'>
                                    {{i[7]}}
                                </td>
                                <td>
                                    <button type="button" class="btn btn-link" onclick="del_open({{i[0]}})">
                                         <span class="glyphicon glyphicon-remove" style="color: Red"></span>
                                    </button>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--    <script src="static/js/up_ps.js"></script>-->
<script type="text/javascript">
function up_ps(){
    var p1=document.getElementById("password1").value;
    var p2=document.getElementById("password2").value;
    var username=document.getElementById('adm_username').innerText;
    var form= new FormData(document.getElementById("lc_up_pass"));
    form.append('username',username)
    if(p1!=p2){
        alert("两次密码不相同。");
        return true;
    }
    $.ajax({
            url:"{{ url_for('lcy_up_pas') }}",
            type:"post",
            data:form,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("更新成功");
                }else{
                    alert("更新失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function log_out(){
    $.ajax({
            url:"{{ url_for('lcy_log_out') }}",
            type:"post",
            data:null,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    open(location, '_self').close();
                }else{
                    alert("退出失败");
                }
            },
            error:function(e){
                alert("error");
            }
        })
       return true;
}
function up_stu(){
    var form= new FormData(document.getElementById("lc_stu"));
    var ls='#stu'+document.getElementById('xh').value;
    $.ajax({
            url:"{{ url_for('lcy_up_stu') }}",
            type:"post",
            data:form,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("更新成功");
                    $(ls).empty();
                    $(ls).prepend(dat.text);
                }else{
                    alert("更新失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function cr_stu(){
    var form= new FormData(document.getElementById("lc_stu"));
    $.ajax({
            url:"{{ url_for('lcy_cr_stu') }}",
            type:"post",
            data:form,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("创建成功");
                    $('#stu_tbody').prepend(dat.text);
                    $('#xh').val(dat.xh);
                }else{
                    alert("创建失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function del_stu(x){
    var ls='#stu'+x;
    var data=new FormData();
    data.append('id',x);
    $.ajax({
            url:"{{ url_for('lcy_del_stu') }}",
            type:"post",
            data:data,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("删除成功");
                    $(ls).remove();
                }else{
                    alert("删除失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function to_stu(x){
    var xh=document.getElementById('stu_xh'+x).innerText;
    var xm=document.getElementById('stu_xm'+x).innerText;
    var bj=document.getElementById('stu_bj'+x).innerText;
    var xb=document.getElementById('stu_xb'+x).innerText;
    var cs=document.getElementById('stu_cs'+x).innerText;
    var mm=document.getElementById('stu_mm'+x).innerText;
    $('#xh').val(xh);
    $('#xm').val(xm);
    $('#bj').val(bj);
    if(xb=='男')
        $('#xb_nan').prop("checked", "checked");
    else
         $('#xb_nv').prop("checked", "checked");
    $('#sr').val(cs);
    $('#mm').val(mm);
    return true;
}
function to_open(x){
    var bh=document.getElementById('op_bh'+x).innerText;
    var kh=document.getElementById('op_kh'+x).innerText;
    var js=document.getElementById('op_js'+x).innerText;
    var cl=document.getElementById('op_cl'+x).innerText;
    var xs=document.getElementById('op_xs'+x).innerText;
    var xf=document.getElementById('op_xf'+x).innerText;
    var rl=document.getElementById('op_rl'+x).innerText;
    $('#bh').val(bh);
    $('#kh').val(kh);
    $('#js').val(js);
    $('#cl').val(cl);
    $('#xs').val(xs);
    $('#xf').val(xf);
    $('#rl').val(rl);
    return true;
}
function up_open(){
    var form= new FormData(document.getElementById("lc_op"));
    var ls='#open'+document.getElementById('bh').value;
    $.ajax({
            url:"{{ url_for('lcy_up_open') }}",
            type:"post",
            data:form,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("更新成功");
                    $(ls).empty();
                    $(ls).prepend(dat.text);
                }else{
                    alert("更新失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function cr_open(){
    var form= new FormData(document.getElementById("lc_op"));
    $.ajax({
            url:"{{ url_for('lcy_cr_open') }}",
            type:"post",
            data:form,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("创建成功");
                    $('#open_tbody').prepend(dat.text);
                    $('#bh').val(dat.bh);
                }else{
                    alert("创建失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function del_open(x){
    var ls='#open'+x;
    var data=new FormData();
    data.append('id',x);
    $.ajax({
            url:"{{ url_for('lcy_del_open') }}",
            type:"post",
            data:data,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    alert("删除成功");
                    $(ls).remove();
                }else{
                    alert("删除失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function ser_open(){
    var data=new FormData();
    data.append('kh',document.getElementById("ope_kh").value);
    data.append('js',document.getElementById("ope_js").value);
    data.append('bj',document.getElementById("ope_bj").value);
    $.ajax({
            url:"{{ url_for('lcy_ser_open') }}",
            type:"post",
            data:data,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    $('#open_tbody').empty();
                    for(var i in dat.data){
                        $('#open_tbody').append(dat.data[i]);
                    }
                }else{
                    alert("搜索失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
function ser_stu(){
    var data=new FormData();
    data.append('xh',document.getElementById("ser_xh").value);
    data.append('xm',document.getElementById("ser_xm").value);
    data.append('bj',document.getElementById("ser_bj").value);
    $.ajax({
            url:"{{ url_for('lcy_ser_stu') }}",
            type:"post",
            data:data,
            processData:false,
            contentType:false,
            success:function(dat){
                if(dat.flag){
                    $('#stu_tbody').empty();
                    for(var i in dat.data){
                        $('#stu_tbody').append(dat.data[i]);
                    }
                }else{
                    alert("搜索失败");
                }
            },
            error:function(e){
                    alert("error");
            }
        })
    return true;
}
</script>
</body>
</html>
